package com.reservationserver.controller.admin;

import com.reservationpojo.domin.vo.AdminBadmintonvo;
import com.reservationpojo.entity.Badminton;
import com.reservationpojo.sendmessageevent.Sse;
import com.reservationpojo.utils.Result;
import com.reservationserver.mapper.admin.AdminBadmintonMapper;
import com.reservationserver.mapper.admin.AdminPingpongMapper;
import com.reservationserver.service.admin.AdminBadmintonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Locked;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/adminbadminton")
@Tag(name = "羽毛球管理界面")
public class AdminbadmintonController {

    private final AdminBadmintonMapper adminBadmintonMapper;
    private final AdminBadmintonService adminBadmintonService;
    /**
     * 扫码入场
     * @param badminton
     * @return 预约记录列表
     * ce
     */
    @Operation(summary = "查询任意预约")
    @GetMapping("/selectreservation")
    public Result selectreservation(@RequestBody AdminBadmintonvo badminton){
        log.info("badminton:{}",badminton);
        log.info("查询预约记录");
        return Result.success(adminBadmintonService.selectreservation(badminton));
    }
    /**
     * 取消预约
     * @param badminton
     * @return
     * ce
     */
    @Operation(summary = "取消指定预约")
    @PostMapping("/deleteReservation")
    public Result deleteReservation(@RequestBody Badminton badminton){
        log.info("管理员取消指定预约：{}",badminton);
        adminBadmintonService.deleteReservation(badminton);
        return Result.success("已取消该预约");
    }
    //ce
    @Operation(summary = "管理员扫码入场")
    @PostMapping("/checkReservation")
    public Result checkReservation(@RequestBody Badminton badminton){
        log.info("管理员扫码入场");
        if(adminBadmintonService.checkReservation(badminton)==null){
            return Result.success("无预约信息");
        }
        return Result.success("可入场");
    }
    //ce
    @Operation(summary = "关闭指定场地")
    @PostMapping("/shutDownCourt")
    public Result shutDownCourt(String courtId, LocalDateTime startTime){
        if(startTime.minusDays(2).isAfter(LocalDateTime.now())){
            return Result.success("不可关闭两天以内的场地");
        }
        log.info("关闭场地：{}",courtId);
        adminBadmintonService.shutDownCourt(courtId,startTime);
        return Result.success("已关闭场地"+courtId);
    }
    //ce
    @Operation(summary = "开启指定场地")
    @GetMapping("/openCourt")
    public Result openCourt(String courtId){
        log.info("开启场地");
        adminBadmintonService.openCourt(courtId);
        return Result.success("已开启场地");
    }
    //ce
    @Operation(summary = "查看被关闭场地")
    @GetMapping("/checkCourt")
    public Result checkCourt(){
        log.info("查看场地");
        return Result.success(adminBadmintonService.checkCourt());
    }
    @Operation(summary = "查询是否允许预约")
    @GetMapping("/serepeate")
    public Result serepeate(){
        log.info("查看是否允许重复预约");
        return Result.success(adminBadmintonMapper.serepeate());
    }
    @Operation(summary = "是否允许重复预约")
    @GetMapping("/uprepeate")
    public Result uprepeate(){
        log.info("修改是否允许重复预约");
        adminBadmintonMapper.uprepeate();
        return Result.success();
    }
}
